package com.ls.blog.config;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @program: myblog
 * @author: lishun
 * @create: 2021-07-12 17:14
 **/
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                // 开启swagger,默认为true
                .enable(true)
                .select()
                // RequestHandlerSelectors配置要扫描接口的方式
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfo(
                "Title",
                "swagger学习",
                "v1.0",
                "termsOfServiceUrl",
                contact(),
                null,
                null,
                new ArrayList<>()
        );
    };

    private Contact contact(){
        return new Contact("lishun","1234.com","123.com");
    }
}
